﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Xml.Linq;

namespace RFW.Silverlight.Weather
{
	public class Temperature
	{
		public string Description { get; set; }
		public double F { get; set; }
		public double C { get; set; }
		public double Humidity { get; set; }

		public override string ToString()
		{
			return this.Description;
		}

		internal void Process(XDocument doc)
		{
			var data = from o in doc.Descendants("current_observation")
						   select new Temperature
						   {
							   Description = o.Element("temperature_string").Value,
							   F = Convert.ToDouble(o.Element("temp_f").Value),
							   C = Convert.ToDouble(o.Element("temp_c").Value),
							   Humidity = Convert.ToDouble(o.Element("relative_humidity").Value)
						   };

			foreach (Temperature o in data)
			{
				this.Description = o.Description;
				this.F = o.F;
				this.C = o.C;
				this.Humidity = o.Humidity;
			}
		}
	}
}
